using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;

namespace sCicero
{
    public class Results : Base
    {
        private const string RESULTS = "testlink_students";

        public Results(ref Data oData)
        {
            m_Table = RESULTS;
            m_oData = oData;
        }

        public Errorcode Edit(int nResultId, int nStudentId, string sComment, DateTime oDate, int nGrade, int nTestId)
        {
            Hashtable oCols = new Hashtable();
            oCols.Add("student_id", nStudentId);
            oCols.Add("comment", sComment);
            oCols.Add("date", oDate);
            if (nGrade > 0)
                oCols.Add("grade_id", nGrade);

            oCols.Add("test_id", nTestId);
            Errorcode oE = m_oData.Edit(ref m_oData, RESULTS, nResultId, oCols);
            if (oE != Errorcode.NOERROR)
                m_LastError = m_oData.LastError();
            return oE;
        }


        public Errorcode Edit(int nStudentId, string sComment, DateTime oDate, int nGrade, int nTestId)
        {
            Hashtable oCols = new Hashtable();
            oCols.Add("student_id",nStudentId);
            oCols.Add("comment", sComment);
            oCols.Add("date", oDate);
            if (nGrade > 0)
                oCols.Add("grade_id", nGrade);

            oCols.Add("test_id", nTestId);
            Errorcode oE = m_oData.Edit(ref m_oData, RESULTS, "student_id = " + nStudentId.ToString() + " and test_id = " + nTestId.ToString(), oCols);
            if (oE != Errorcode.NOERROR)
                m_LastError = m_oData.LastError();
            return oE;
        }

        public Errorcode New(int nStudentId, string sComment, DateTime oDate, int nGrade, int nTestId)
        {
            Hashtable oCols = new Hashtable();
            oCols.Add("student_id", nStudentId);
            oCols.Add("comment", sComment);
            oCols.Add("date", oDate);
            if (nGrade > 0)
                oCols.Add("grade_id", nGrade);

            oCols.Add("test_id", nTestId);
            Errorcode oE = m_oData.New(ref m_oData, RESULTS, oCols);
            if (oE != Errorcode.NOERROR)
                m_LastError = m_oData.LastError();
            return oE;
        }
    }
}


